<?php

	class GP_page_mailing_list extends GP_controleur
	{
		var $controleur;
		var $db;
		
		function __construct()
		{
			global $page;
			$this -> controleur = parent::getInstance($page);
		}
		
		function form()
		{
			extract($_POST);
			$q = "SELECT id FROM _fo_mailing_list WHERE surname = '".addslashes($surname)."' && email = '".addslashes($email)."'";
			$res = $this -> db -> fetchArray_one($q);
			if (count($res))
				header('Location: ' . URL_SITE . 'newsletter/error/');
			else
			{
				if (is_utf8($firstname)) utf8_decode($firstname);
				if (is_utf8($surname)) utf8_decode($surname);
				if (is_utf8($firstname)) utf8_decode($firstname);
				if (is_utf8($address)) utf8_decode($address);
				if (is_utf8($address_2)) utf8_decode($address_2);
				if (is_utf8($city)) utf8_decode($city);
				if (is_utf8($zip)) utf8_decode($zip);
				if (is_utf8($email)) utf8_decode($email);
				if (is_utf8($birthdate)) utf8_decode($birthdate);
				
				$insert_ml = "INSERT INTO _fo_mailing_list SET
				firstname = '".addslashes($firstname)."',
				surname = '".addslashes($surname)."',
				address = '".addslashes($address)."',
				address_2 = '".addslashes($address_2)."',
				zip = '".addslashes($zip)."',
				city = '".addslashes($city)."',
				country = '".addslashes($country)."',
				email = '".addslashes($email)."',
				birthdate = '".addslashes($birthdate)."',
				datecrea = NOW(),
				datemodif = NOW()";
				$this -> db -> requete($insert_ml);
				header('Location: ' . URL_SITE . 'newsletter/confirmation/');
			}
		}
		
		function afficher()
		{			
			global $page, $urirw;
			if (strlen($urirw))
			{
				$pagerw = fakeurl($urirw);
				$htmltmp = $this -> controleur -> htmlrw('header');
				$htmltmp .= $this -> controleur -> htmlrw($page);
				$htmltmp .= $this -> controleur -> htmlrw('footer');
				savefile($pagerw, $htmltmp);
				include($urirw);
			}
			else
			{
				$this -> controleur -> add_html('header');
				$this -> controleur -> add_html($page);
				$this -> controleur -> add_html('footer');
			}
		}
		
		function setvar($var, $val)
		{
			global $urirw;
			if (strlen($urirw))
				$this -> $var = $val;
			else
				$this -> controleur -> $var = $val;
		}
	}
	
	$page_mailing_list = new GP_page_mailing_list;
	$page_mailing_list -> db = GP_db :: getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
	$gp_request = GP_secure:: getInstance();
	
	$page = $gp_request -> Get('page', $GLOBALS["page"]);
	$action_form = $gp_request -> Get('action_form');
	
	if ($action_form == 1)
		$retour_form = $page_mailing_list -> form();
	
	$page_mailing_list -> setvar('titre', 'Subscribe to mailing list - Comme des Garcons');
	$page_mailing_list -> setvar('meta_keywords', 'mailing list, comme des garcons');
	$page_mailing_list -> setvar('meta_description', 'Subscribe to mailing list - Comme des Garcons');
	$page_mailing_list -> setvar('page', $page);
	$page_mailing_list -> afficher();
?>